'''
    This file is part of Ognom Keeper.

    Ognom Keeper is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ognom Keeper is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ognom Keeper.  If not, see <http://www.gnu.org/licenses/>.


    Copyright(C) 2009 Viktor Vestberg
'''

try: 
    import pygame, os, math, sys, glob
    import pickle as pickle  # For loading and saving files
    from pymunk import *
    from pymunk import Vec2d
    from pymunk.util import *
except ImportError, err:
    print str("couldn't load module. %s" % (err))
    
def nothing():
    return 'no value'

class Window():
    def __init__(self, width=800, height=600, caption="untitled", flags=0, icon=None):
        self.resolution = [width, height]   
        self.fullscreen = False
        self.screen = pygame.display.set_mode(self.resolution, flags)
        pygame.display.set_caption(caption)
        self.rect = self.screen.get_rect()
        if icon is not None: pygame.display.set_icon(icon)
    def update(self):
        #pygame.display.flip()
        pygame.display.update(self.rect)
    def getResolution(self):
        return pygame.display.get_surface().get_size()
    def toggleFullscreen(self):
        if self.fullscreen is False: 
            self.screen = pygame.display.set_mode(self.resolution, pygame.FULLSCREEN)
            self.fullscreen = True
        elif self.fullscreen:
            self.screen = pygame.display.set_mode(self.resolution)
            self.fullscreen = False
        
def load_sound(name):
    class NoneSound:
        def play(self): pass
    if not pygame.mixer:
        return NoneSound()
    fullname = os.path.join('data', name)
    try: sound = pygame.mixer.Sound(fullname)
    except pygame.error, message:
        print "Cannot load sound: ", name
        raise SystemExit, message
    return sound 

def load_image(name, colorkey=[255,0,255], path='data'):
    fullname = os.path.join(path, name)
    try:
        image = pygame.image.load(fullname)
    except pygame.error, message:
        print "Cannot load image: ", name
        raise SystemExit, message
    image = image.convert()
    if colorkey is not None:
        if colorkey is -1:
            colorkey = image.get_at((0,0))
        image.set_colorkey(colorkey, pygame.RLEACCEL)
    return image, image.get_rect()

class Level:
    """The Level class is not a Part. It stores different data then is stored in a text file using pickle"""
    def __init__(self):
        self.wallPoints = [] 
        self.playerStartPos = None
        self.finishPoints = []
        self.badWallPoints = []
        self.bounceWallPoints = []
        self.bgPicture = None
        self.bgRect = None
        self.bgSurface = None
        
class HiScore:
    def __init__(self):
        self.scores = []
        
def to_radian(degree):
    return (degree*math.pi)/(180)
def to_degree(radian):
    return (radian*180)/(math.pi)

def NoCollision(shape1, shape2, contact_points, num_contact_points, data):
    return False
